package com.example.demo.service.handler;

import com.example.demo.service.WxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class WxMessageFactory implements IWxMessageFactory {
    public static final String TYPE_TEXT = "text";
    public static final String TYPE_EVENT = "event";
    public static final String TYPE_IMAGE = "image";

    @Autowired
    private WxUserService wxUserService;

    @Override
    public IWxMessageHandler createMessage(String messageType) {
        IWxMessageHandler iWxMessageHandler = null;
        switch (messageType) {
            case TYPE_TEXT:
                iWxMessageHandler = new WxTextMessage();
                break;
            case TYPE_EVENT:
                iWxMessageHandler = new WxEventMessage();
                break;
            default:
                break;
        }
        if (iWxMessageHandler != null) {
            iWxMessageHandler.setHandlerService(wxUserService);
        }
        return iWxMessageHandler;
    }
}
